<template>
  <div class="app-viewer">
    <div class="viewer-header">
      <el-row>
        <el-col :span="12">
          <el-row :gutter="10" class="mb20">
            <el-col :span="1.5">
              <el-button type="primary" @click="handleAdd" v-hasPermi="['data:info:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button plain :disabled="multiple" @click="handleDelete" v-hasPermi="['data:info:remove']">删除</el-button>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="12" style="text-align: right">
          <transition name="fade">
            <span v-show="!isShowQuery" style="margin-right: 10px">
              <el-input v-model="queryParams.fireName" placeholder="请输入所属火区地址"
                style="width: 200px; margin-right: 10px"></el-input>
              <el-button type="primary" @click="handleQuery">查询</el-button>
              <el-button type="primary" @click="resetQuery">重置</el-button>
            </span>
          </transition>
          <!-- <el-button type="primary" @click="switchQuery">
            {{ isShowQuery ? "普通检索" : "高级检索" }}
          </el-button>-->
        </el-col>
      </el-row>
      <!-- <el-collapse-transition>
        <div class="query" v-show="isShowQuery">
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="100px"
            @submit.native.prevent
          >
            <el-form-item prop="fireName">
              <el-input
                v-model="queryParams.fireName"
                placeholder="请输入所属火区地址"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          
            <el-form-item>
              <el-button type="primary" @click="handleQuery">搜索</el-button>
              <el-button type="primary" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-collapse-transition>-->
    </div>

    <div class="viewer-body">
      <el-table :data="infoList" border :header-cell-style="{
        background: '#Fff',
        fontFamily: 'AlibabaPuHuiTi-2-55-Regular',
      }" @selection-change="handleSelectionChange">
        <el-table-column type="selection" align="center" />
        <el-table-column label="所属火区" width="200" align="center" prop="fireName" show-overflow-tooltip />
        <el-table-column prop="lonAndLat" align="center" width="150" label="经纬度"></el-table-column>
        <el-table-column label="影像" align="center" prop="cfeCoalfieldBasicImageList" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-for="(item2, i2) in scope.row.cfeCoalfieldBasicImageList" :key="i2" style="margin-left: 20px">{{
              item2.imageTime }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <div class="hanlderArea">
              <div @click="handleUpdate(scope.row)" class="checkDetail">
                编辑
              </div>
              <div @click="handleDetail(scope.row)" class="checkDetail">
                查看
              </div>
              <div @click="handleExport(scope.row)" class="checkDetail">
                导出
              </div>
              <div @click="handleYingxiang(scope.row)" class="checkDetail">
                影像配置
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" layout="total, prev,pager,next" :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize" @pagination="getPageData" />
    </div>

    <FireDialoag ref="dialog" :serviceRefresh="getList" :dialogTitle="dialogTitle" />
    <!-- 影像配置 -->

    <el-dialog title="影像配置" width="40%" :visible.sync="yingXiangOpen" @closed="closeYingXiangDialog"
      :modal-append-to-body="false">
      <!-- <div class="server-header">
        <div class="time item">日期</div>
        <div class="address item">服务地址</div>
        <div class="name item">服务名称</div>
      </div>
      <div class="yingxiang" v-for="(item, i) in yingXiangList" :key="i">
        <el-date-picker v-model="item.imageTime" style="width: 150px" type="date" placeholder="选择日期"
          value-format="yyyy-MM-dd"></el-date-picker>
        <el-input v-model="item.imageAddress" style="margin-left: 20px; width: 163px" placeholder="请输入影像名称"></el-input>
        <el-input v-model="item.imageAddress" style="margin-left: 20px; width: 163px" placeholder="请输入影像地址"></el-input>

        <div class="clearBtn" @click="clearYingXiangHandler(i)">
          <i class="el-icon-close"></i>
        </div>
      </div> -->
      <el-table class="server-table" :data="yingXiangList" style="width: 100%" border>
        <el-table-column prop="imageTime" label="日期" #default="{ row }">
          <el-date-picker v-model="row.imageTime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"
            style="width: 100%;"></el-date-picker>
        </el-table-column>
        <el-table-column prop="imageName" label="服务名称" #default="{ row }">
          <el-input v-model="row.imageName" placeholder="请输入服务名称"></el-input>
        </el-table-column>
        <el-table-column prop="imageAddress" label="服务地址" #default="{ row }">
          <el-input v-model="row.imageAddress" placeholder="请输入服务地址"></el-input>
        </el-table-column>
        <el-table-column label="操作" #default="{ row }" width="80px" align="center">
          <el-button type="text" @click="clearYingXiangHandler(row)">删除</el-button>
        </el-table-column>
      </el-table>

      <div class="yingxiangAdd" @click="addYingXiangHandler">
        <i class="el-icon-plus"></i>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelYingXiang">取 消</el-button>
        <el-button type="primary" @click="submitYingXiang">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  fireList,
  delFire,
  fireImageSet,
  checkFireDetails,
} from "@/api/data/houtai";
import axios from "axios";
import FireDialoag from "./CreateOrUpdateDialog";
import { getToken } from "@/utils/auth";

let intervalKey;
export default {
  components: { FireDialoag },
  computed: {
    dialogTitle: function () {
      // if (this.dialogStatus === "create") {
      //   return "添加火区";
      // } else if (this.dialogStatus === "detail") {
      //   return "火区详情";
      // } else if (this.dialogStatus === "edit") {
      //   return "修改火区";
      // }
      return "";
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 列表数据
      infoList: [],
      allList: [],
      // titleYingXiang: "影像配置",
      // 非多个禁用
      multiple: true,
      yingXiangOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sorId: "",
        fireName: "",
      },
      isShowQuery: false,

      //温度y值
      sensortempList: [],
      //气压y值
      sensorvoltageList: [],

      curFire: NaN,
      imageTime: "",
      imageAddress: "",
      yingXiangList: [],
      dialogStatus: "",
      FireDetailData: {},
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    // 接收路由跳转参数
    this.getRouterPara();
  },
  beforeDestroy() {
    if (intervalKey) {
      clearInterval(intervalKey);
    }
  },
  methods: {
    getRouterPara() {
      this.FireDetailData = this.$route.query.FireDetailData || {};
      this.queryParams.fireName = this.FireDetailData.fireName;
      intervalKey = setTimeout(() => {
        this.handleQuery();
      }, 1000);
    },
    /** 查询数据列表 */
    getList() {
      this.$modal.loading("正在努力请求数据，请稍候...");
      fireList({
        ...this.queryParams,
        sorId:
          Number(this.queryParams.sorId) == 0
            ? undefined
            : Number(this.queryParams.sorId),
      }).then((response) => {
        this.allList = response.data.rows.map((item) => {
          const ojb = { ...item };
          if (item.longitude && item.latitude) {
            ojb.lonAndLat =
              item.longitude.toFixed(3) + "," + item.latitude.toFixed(3);
          }

          return ojb;
        });
        this.total = response.data.total;
        this.infoList = this.allList.slice(
          (this.queryParams.pageNum - 1) * this.queryParams.pageSize,
          this.queryParams.pageNum * this.queryParams.pageSize
        );
        this.$modal.closeLoading();
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        sorId: "",
        fireName: "",
      };
      this.handleQuery();
    },
    switchQuery() {
      this.isShowQuery = !this.isShowQuery;
      this.queryParams.sorId = "";
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.dialogStatus = "create";
      this.$refs["dialog"].openDialog("create");
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.dialogStatus = "edit";
      checkFireDetails(row.id).then((response) => {
        this.form = response.data;
        this.form.id = row.id;
        if (this.form.latitude && this.form.longitude)
          this.form.firejwd = this.form.longitude + " ；" + this.form.latitude;
        this.$refs["dialog"].openDialog("edit", this.form);
      });
    },
    /** 查看 */
    handleDetail(row) {
      this.dialogStatus = "detail";
      checkFireDetails(row.id).then((response) => {
        this.form = response.data;
        this.form.id = row.id;
        this.$refs["dialog"].openDialog("detail", this.form);
      });
    },
    // 取消按钮
    cancelYingXiang() {
      this.yingXiangOpen = false;
    },
    //添加影像
    addYingXiangHandler() {
      const obj = {
        imageTime: "",
        imageAddress: "",
        imageName: ''
      };
      this.yingXiangList.push(obj);
    },
    //删除影像
    clearYingXiangHandler(row) {
      const i = this.yingXiangList.indexOf(row)
      if (i > -1) this.yingXiangList.splice(i, 1);
    },
    /** 提交按钮 */
    submitYingXiang() {
      let isFull = true;
      this.yingXiangList.map((item) => {
        if (item.imageTime === "" || item.imageAddress === "") {
          isFull = false;
        }
        return;
      });
      if (!isFull) {
        this.$modal.msgError("影像时间或地址不能为空");
        return;
      }
      fireImageSet({
        id: this.curFire.id,
        cfeCoalfieldBasicImageList: this.yingXiangList,
      })
        .then(() => {
          this.$modal.msgSuccess("影像配置成功");
          this.yingXiangOpen = false;
          this.getList();
        })
        .catch((error) => {
          reject(error);
        });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("删除为重要数据，请确认是否删除？")
        .then(() => {
          this.$confirm("删除为重要数据，请再次确认是否删除？", "系统提示", {
            confirmButtonText: '取消',
            cancelButtonText: '确认',
            confirmButtonClass: 'houtai-fire-confirm-button',
            cancelButtonClass: 'houtai-fire-cancel-button'
          })
            .then(() => { })
            .catch(() => {
              delFire(ids).then(() => {
                this.resetQuery();
                this.$modal.msgSuccess("删除成功");
              });
            });
        })
        .catch(() => { });
    },
    closeYingXiangDialog() {
      this.yingXiangOpen = false;
      this.curFire = null;
    },

    /** 导出按钮操作 */
    handleExport(row) {
      const baseURL = process.env.VUE_APP_BASE_API;
      axios
        .get(baseURL + "/data/basic/exportZip/" + row.id, {
          responseType: "blob",
          headers: { Authorization: "Bearer " + getToken() },
        })
        .then(({ data }) => {
          const link = document.createElement("a");
          const blob = new Blob([data]);
          link.href = URL.createObjectURL(blob);
          link.download = `${row.fireName}.zip`;
          link.click();
          URL.revokeObjectURL(link.href);
        });
      // axios
      //   .get(baseURL + "/data/basic/exportPdf/" + row.id, {
      //     responseType: "blob",
      //   })
      //   .then(({ data }) => {
      //     const link = document.createElement("a");
      //     const blob = new Blob([data]);
      //     link.href = URL.createObjectURL(blob);
      //     link.download = `${row.fireName}.pdf`;
      //     link.click();
      //     URL.revokeObjectURL(link.href);
      //   });
    },
    //配置影像
    handleYingxiang(row) {
      this.curFire = row;
      this.yingXiangList = row.cfeCoalfieldBasicImageList.map((item) => {
        const obj = {
          imageTime: item.imageTime,
          imageAddress: item.imageAddress,
          imageName: item.imageName,
          basicId: row.id,
        };
        return obj;
      });
      this.yingXiangOpen = true;
    },
    // 分页
    getPageData() {
      this.infoList = this.allList.slice(
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize,
        this.queryParams.pageNum * this.queryParams.pageSize
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.yingxiang {
  display: flex;
  justify-content: flex-start;
  flex-direction: row;
  margin-top: 20px;

  .clearBtn {
    margin-left: 20px;
    line-height: 36px;
    cursor: pointer;
  }
}

.yingxiangAdd {
  width: 100%;
  height: 30px;
  // background: #ccc;
  border: 1px solid #ccc;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  margin-top: 20px;
}

.query {
  border-top: 1px solid #dfe6ec;
  border-bottom: 1px solid #dfe6ec;
  text-align: right;
}

.query>>>.el-form--inline .el-form-item {
  margin-right: 0;
  margin-left: 10px;
  margin-bottom: 14px;
  margin-top: 14px;
}

.app-container>>>.el-button--text:hover {
  border-color: #0000;
  background: #0000;
}

::v-deep .el-table th.el-table__cell.is-leaf,
.el-table td.el-table__cell {
  border-bottom: 1px solid #4b5057 !important;
}

::v-deep .el-table::before,
.el-table--group::after,
.el-table--border::after {
  border: solid 1px #4b5057 !important;
}

::v-deep .el-table--border:after,
.el-table--group:after,
.el-table:before {
  background-color: #4b5057 !important;
}

::v-deep .el-table--border,
.el-table--group {
  border-color: #4b5057 !important;
}

::v-deep.el-table td,
.el-table th.is-leaf {
  border-bottom: 1px solid #4b5057 !important;
}

::v-deep .el-table--border th,
.el-table--border th.gutter:last-of-type {
  border-bottom: 1px solid #4b5057 !important;
}

::v-deep.el-table--border td,
.el-table--border th {
  border-right: 1px solid #4b5057 !important;
}

::v-deep .el-table th.el-table__cell.is-leaf,
.el-table td.el-table__cell {
  border-bottom: 1px solid rgba(255, 255, 255, 0.17);
  border-right: 1px solid #4b5057 !important;
}

::v-deep .el-table tbody tr:hover>td {
  background-color: #1d2125 !important;
  color: #ffffff;
}

.hanlderArea {
  display: flex;
  justify-content: space-around;
  flex-direction: row;

  .checkDetail {
    font-family: "AlibabaPuHuiTi-2-55-Regular";
    font-size: 15px;
    font-weight: normal;
    font-stretch: normal;
    letter-spacing: 1px;
    color: #005aff;
    cursor: pointer;
  }
}

.server-header {
  display: flex;

  .item {
    line-height: 26px;
  }

  .time {
    width: 163px;
  }

  .address,
  .name {
    width: 163px;
  }
}

::v-deep .server-table {
  border-color: #dfe6ec !important;
  background-color: #e6ebf5 !important;


  .el-table__header,
  .el-table__body-wrapper {
    background-color: #FFFFFF !important;

    tr {
      background-color: #FFFFFF !important;
    }

    .el-table__cell.is-leaf {
      background-color: #FFFFFF !important;
      border-right: 1px solid #dfe6ec !important;
      border-bottom: 1px solid #dfe6ec !important;
    }
  }

  .el-table__cell {
    color: #4b5057;
  }

  td {
    border-right: 1px solid #dfe6ec !important;
    border-bottom: 1px solid #dfe6ec !important;
  }

  .el-table__body tr:hover>td.el-table__cell {
    background-color: #f9f9f9 !important;
  }
}

::v-deep .server-table {

  &:after,
  &:before {
    background-color: #dfe6ec !important;
  }

  &::after,
  &::before {
    border-color: #dfe6ec !important;
  }
}
</style>

<style lang="scss">
// .lcj-select-popup {
// background: #08102a !important;
// border: none !important;
// color: #fff !important;
// .el-picker-panel__footer {
//   border: 1px solid rgba(255, 255, 255, 0.17) !important;
//   background-color: #08102a;
// }
// .el-date-range-picker__time-header,
// .el-date-table th {
//   border-bottom: 1px solid rgba(255, 255, 255, 0.17);
// }
// .el-date-range-picker__content.is-left {
//   border-bottom: 0px solid rgba(255, 255, 255, 0.17);
// }
// .el-time-panel__content.has-seconds::before,
// .el-time-panel__content.has-seconds::after {
//   border-bottom: 1px solid #5c5e63;
//   border-top: 1px solid #5c5e63;
// }
// .el-time-panel__btn {
//   border: none;
//   line-height: 28px;
//   padding: 0 5px;
//   margin: 0 5px;
//   cursor: pointer;
//   font-family: "AlibabaPuHuiTi-2-105-Heavy";
//   font-size: 14px;
//   color: #009688;
// }

// .el-time-panel__btn.confirm,
// .el-time-spinner__item.active:not(.disabled) {
//   font-weight: 800;
//   color: #009688;
// }
// .el-time-spinner__item:hover:not(.disabled):not(.active) {
//   background: transparent;
//   color: #009688;
//   cursor: pointer;
// }
// .el-date-range-picker__content.is-left {
//   border-right: 1px solid rgba(255, 255, 255, 0.17);
// }
// .el-time-panel,
// .el-time-panel__footer {
//   border-top: 1px solid rgba(255, 255, 255, 0.17);
//   background-color: #08102a;
//   border: 1px solid rgba(255, 255, 255, 0.17);
// }
// .popper__arrow {
//   border-bottom-color: #439eff !important;
//   &::after {
//     border-bottom-color: #08102a !important;
//   }
// }
// .el-input__inner,
// .el-input.is-disabled .el-input__inner {
//   height: 36px;
//   line-height: 36px;
//   background: #1b3663;
//   color: #fff;
//   font-family: "AlibabaPuHuiTi-2-55-Regular";

//   border: none;
// }
// .el-button.is-disabled.is-plain,
// .el-button.is-disabled.is-plain:hover,
// .el-button.is-disabled.is-plain:focus {
//   background-color: transparent !important;
//   border: none !important;
//   color: #c0c4cc !important;
// }
// .el-button + .el-button,
// .el-button--text {
//   background: transparent;
//   border: none;
//   span {
//     font-family: "AlibabaPuHuiTi-2-105-Heavy";
//     font-size: 16px;
//     color: #25b390;
//   }
// }
// .el-select-dropdown__item {
//   color: #fff;
//   &:hover {
//     background: rgba(10, 152, 188, 0.3);
//     color: #202d38;
//   }
// }
// .el-select-dropdown__item.hover {
//   background: rgba(10, 152, 188, 0.3);
//   color: #202d38;
// }
// .el-scrollbar__wrap {
//   overflow-x: hidden;
//   margin-bottom: 0 !important;
// }
// .el-cascader-menu {
//   border-right: solid 1px #439eff;
// }
// // .el-radio {
// //   display: none;
// // }
// .el-cascader-node.in-active-path,
// .el-cascader-node.is-selectable.in-checked-path,
// .el-cascader-node.is-active {
//   color: rgba(10, 152, 188, 0.3);
//   font-weight: bold;
// }
// .el-date-table td.in-range div,
// .el-date-table td.in-range div:hover,
// .el-date-table.is-week-mode .el-date-table__row.current div,
// .el-date-table.is-week-mode .el-date-table__row:hover div {
//   background-color: transparent;
// }
// .el-date-table td.end-date span,
// .el-date-table td.start-date span {
//   background-color: #08102a;
// }
// .el-cascader-node__label {
//   color: #fff;
//   z-index: 1;
//   pointer-events: none;
// }
// .el-cascader-node:not(.is-disabled):hover,
// .el-cascader-node:not(.is-disabled):focus {
//   background: #08102a;
// }
// .el-cascader-node__postfix {
//   right: 30px;
//   color: #08102a;
// }
// .el-radio__inner {
//   border: 0;
//   border-radius: 0;
//   width: 170px;
//   height: 34px;
//   background-color: transparent;
//   position: absolute;
//   top: -18px;
//   left: -19px;
// }

// .el-select-dropdown__item {
//   color: #fff;
//   &:hover {
//     background: #08102a;
//     color: #fff;
//   }
//   &:focus {
//     background: #08102a;
//     color: #fff;
//   }
// }
// .el-select-dropdown__item.selected {
//   color: #fff;
//   background: #08102a;
// }
// }
// .el-date-editor {
//   .el-range-input {
//     background: transparent;
//     font-family: "AlibabaPuHuiTi-2-55-Regular";
//     font-size: 14px;
//     font-weight: normal;
//     font-stretch: normal;
//     line-height: 18px;
//     letter-spacing: 0px;
//     color: #cccccc;
//   }
//   .el-range__icon {
//     color: #fff;
//   }
//   .el-range-separator {
//     line-height: 27px !important;
//     width: 7% !important;
//     font-family: "AlibabaPuHuiTi-2-105-Heavy";
//     font-size: 16px;
//     font-weight: normal;
//     font-stretch: normal;
//     line-height: 18px;
//     letter-spacing: 0px;
//     color: #ffffff;
//   }
// }
// .el-date-table td.today span {
//   color: #25b390;
//   font-weight: 700;
//   font-size: 16px;
//   font-family: "AlibabaPuHuiTi-2-105-Heavy";
// }
// .el-date-table td.in-range div,
// .el-date-table td.in-range div:hover {
//   background-color: rgba(37, 179, 144, 0.3) !important;
// }
// .el-date-table td.in-range div,
// .el-date-table td.in-range div:hover,
// .el-date-table.is-week-mode .el-date-table__row.current div,
// .el-date-table.is-week-mode .el-date-table__row:hover div {
//   background-color: transparent;
// }
// .el-date-table td.end-date span,
// .el-date-table td.start-date span {
//   background-color: #25b390;
// }
// .el-popper[x-placement^="top"] .popper__arrow::after,
// .el-popper[x-placement^="top"] .popper__arrow {
//   border-top-color: transparent;
// }
//
</style>

<style  lang="scss">
.houtai-fire-confirm-button,
.houtai-fire-confirm-button:hover,
.houtai-fire-confirm-button:focus {
  border-color: #DCDFE6;
  color: #606266;
  background-color: #FFFFFF;
}

.houtai-fire-cancel-button,
.houtai-fire-cancel-button:hover,
.houtai-fire-cancel-button:focus {
  border-color: #337bff;
  background-color: #005aff;
  color: #FFFFFF;
}
</style>